﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsStore.Repository.Interfaces;
using SportsStore.Model;
using SportsStore.ServicesInterfaces;
using SportsStore.ServicesInterfaces.Interfaces;

namespace SportsStore.ProductService
{
    public class ProductService : IProductService
    {
      readonly IProductRepository _productRepository;

        public ProductService(IProductRepository productRepository)
        {
          _productRepository = productRepository;
        }

        public PagedResult<Product> GetProducts(int pageNumber, int pageItems, string category)
        {
            try
            {
              return _productRepository.GetProducts(pageNumber, pageItems, category);
            }
            catch (Exception e)
            {
                throw new SportsStoreException("Unable to retrieve products", e);
            }
        }

      public Product GetProduct(int id)
      {
        try
        {
          return _productRepository.GetProduct(id);
        }
        catch (Exception e)
        {
          throw new SportsStoreException("Unable to retrieve product");
        }
      }
    }
}
